import os
import time
import shutil
from tqdm import tqdm # pip install tqdm
import concurrent.futures as cf


def main():
    name_list = os.listdir('E:\\smallTools\\python\code\\work_auto12365\\venv2\Scripts\\2022-11-07_115944\\images')
    print(name_list)
    print(__file__)
    # name_list.remove(os.path.basename(__file__))
    # name_list.remove(os.path.basename('E:\\smallTools\\python\code\\work_auto12365\\venv2\Scripts\\2022-11-07_115944\\images'))
    with tqdm(total=len(name_list)) as bar: # 进度条
        with cf.ThreadPoolExecutor() as p: # 线程池
            for name in name_list:
                time_stamp = os.path.getmtime('E:\\smallTools\\python\code\\work_auto12365\\venv2\Scripts\\2022-11-07_115944\\images\\'+name) # 获取文件修改日期时间戳
                time_local = time.localtime(time_stamp) # 将时间戳转换为本地时间
                time_style = time.strftime(r'%Y%m%d', time_local) # 将本地时间转换为指定格式的时间
                os.makedirs(time_style, exist_ok=True)
                p.submit(shutil.move, name, time_style).add_done_callback(lambda func: bar.update())


if __name__ == '__main__':
    main()
